package org.lgiavedoni.android.franq.service.textcat;

import org.lgiavedoni.android.franq.util.textcat.TextCategorizer;

public class TextCategorizingService {
	
	public static final TextCategorizingService ins = new TextCategorizingService();
	
	private final TextCategorizer languageTC = new TextCategorizer();  
	
	public static enum LanguageCategorization{
		GERMAN("german"),
		ENGLISH("english"),
		FRENCH("french"),
		SPANISH("spanish"),
		ITALIAN("italian"),
		SWEDISH("swedish"),
		POLISH("polish"),
		DUTCH("dutch"),
		NORWEGIAN("norwegian"),
		FINNISH("finnish"),
		ALBANIAN("albanian"),
		SLOVAKIAN("slovakian"),
		SLOVENIAN("slovenian"),
		DANISH("danish"),
		HUNGARIAN("hungarian"),
		UNDEFINED("undefined");
		
		private String value;
		
		private LanguageCategorization(String value) {
			this.value = value;
		}
		
		public String getValue(){
			return value;
		}
	}	
	
	private TextCategorizingService(){
		languageTC.setConfFile("util/textcat/language/textcat.conf");
	}
	
	
	/**
	 * This method try to determinate the language in base a one specific text
	 * @param text
	 * @return
	 */
	public LanguageCategorization categoriceLanguage(String text){
		String categorization = languageTC.categorize(text);
		for (LanguageCategorization lCategorization : LanguageCategorization.values()) {
			if(lCategorization.getValue().equals(categorization))
				return lCategorization;
		}
		return LanguageCategorization.UNDEFINED;
		 
	}

}
